import rclpy
from rclpy.node import Node
from std_msgs.msg import Float64


class Pulibsher(Node):
    def __init__(self, name: str):
        super().__init__(name)
        self.command_publisher_ = self.create_publisher(Float64, 'rl_rate', 10)
        # 创建定时器，50hz为周期，定时发布
        self.timer_ = self.create_timer(0.02, self.timer_callback)  # 0.1秒 = 100ms

    def timer_callback(self):
        # 创建消息
        message = Float64()
        message.data = 0.0
        # 发布消息
        self.command_publisher_.publish(message)

def main(args=None):
    rclpy.init(args=args)
    node = Pulibsher("rate_50hz")
    # 运行节点，并检测退出信号
    try:
        rclpy.spin(node)
    except KeyboardInterrupt:
        pass
    finally:
        node.destroy_node()
        rclpy.shutdown()


if __name__ == '__main__':
    main()
